package com.sniff.atp.modules.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sniff.atp.modules.test.mapper.OpsMembershipChangeLogMapper;
import com.sniff.atp.modules.test.model.OpsMembershipChange;
import com.sniff.atp.modules.test.model.OpsMembershipChangeLog;
import com.sniff.atp.modules.test.service.OpsMembershipChangeLogService;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 赠送会员日志 服务实现类
 * </p>
 *
 * @author macro
 * @since 2023-12-12
 */
@Service
public class OpsMembershipChangeLogServiceImpl extends ServiceImpl<OpsMembershipChangeLogMapper, OpsMembershipChangeLog> implements OpsMembershipChangeLogService {

    @Override
    public boolean create(OpsMembershipChangeLog opsMembershipChangeLog) {
        opsMembershipChangeLog.setCreateTime(new Date());
        opsMembershipChangeLog.setCreateTime(new Date());
        return save(opsMembershipChangeLog);
    }

    @Override
    public boolean update(Long id, OpsMembershipChangeLog opsMembershipChangeLog) {
        opsMembershipChangeLog.setUpdateTime(new Date());
        return updateById(opsMembershipChangeLog);
    }

    @Override
    public Page<OpsMembershipChangeLog> list(OpsMembershipChangeLog opsMembershipChangeLog, Integer pageSize, Integer pageNum) {
        Page<OpsMembershipChangeLog> page = new Page<>(pageNum, pageSize);
        QueryWrapper<OpsMembershipChangeLog> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(StringUtil.isNotBlank(opsMembershipChangeLog.getCustomerName()), OpsMembershipChangeLog::getCustomerName,opsMembershipChangeLog.getCustomerName())
                .eq(opsMembershipChangeLog.getOpsMembershipChangeId() != null,OpsMembershipChangeLog::getOpsMembershipChangeId,opsMembershipChangeLog.getOpsMembershipChangeId())
                .ge(opsMembershipChangeLog.getStartTime() != null,OpsMembershipChangeLog::getCreateTime,opsMembershipChangeLog.getStartTime())
                .le(opsMembershipChangeLog.getEndTime() != null,OpsMembershipChangeLog::getCreateTime,opsMembershipChangeLog.getEndTime())
                .orderByDesc(OpsMembershipChangeLog::getCreateTime);
        return page(page, wrapper);
    }
}
